var path = require('path');
var PROTO_PATH = path.join(__dirname,'./protos/greeter.proto');

var grpc = require('@grpc/grpc-js');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
    PROTO_PATH,
    {keepCase: true,
     longs: String,
     enums: String,
     defaults: true,
     oneofs: true
    });
var greeterProto = grpc.loadPackageDefinition(packageDefinition).greeter;

function main() {
  var client = new greeterProto.Greeter('127.0.0.1:3001',grpc.credentials.createInsecure());
  client.sayHello({username: "张三",age:20,sex:"男",flag:true}, function(err, response) {
   console.log('Greeting:', response.message);
 })
}

main();